
 // Definition for a binary tree node.

 import java.util.ArrayList;
 import java.util.List;

 class Solution {
    public class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

    List<Integer> count=new ArrayList<Integer>();
    public boolean findTarget(TreeNode root, int k) {
        dfs(root);
        int left=0;
        int right=count.size()-1;
        while(left<right){
            if(count.get(left)+count.get(right)==k){
                return true;
            }
            if(count.get(left)+count.get(right)<k){
                left++;
            }else{
                right--;
            }
        }
        return false;
        
    }
    public void dfs(TreeNode root){
 
        if(root==null){
            return ;
        }
        dfs(root.left);
        count.add(root.val);
        dfs(root.right);
    }
}